//
//  DetailCell.m
//  DayDay
//
//  Created by wade on 16/5/16.
//  Copyright © 2016年 wade. All rights reserved.
//

#import "DetailCell.h"
#import "SVProgressHUD.h"
@implementation DetailCell



- (IBAction)collectionAction:(UIButton *)sender {
    
 
    
    
    // 生成文件存储路径为沙盒下的items.plist
    NSString *dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *path = [dir stringByAppendingPathComponent:@"items.plist"];
    NSLog(@"%@", path);
    
    // 读取
    NSMutableArray *existingItems = [NSMutableArray arrayWithContentsOfFile:path];
    
    
    
    if (!existingItems)
    {
        existingItems = [[NSMutableArray alloc] init];
        [existingItems  addObject:self.imgUrl];
    }
    else
    {
        
        if(![existingItems containsObject:self.imgUrl])
        {
            [existingItems  addObject:self.imgUrl];
        }
        
        
    }
  
   
    UIImageWriteToSavedPhotosAlbum(self.ImgView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
    
    // 写入
    [existingItems writeToFile:path atomically:YES];
    
    [SVProgressHUD showSuccessWithStatus:@"收藏成功"];
    
    
    
}

- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
    NSString *msg = nil ;
    if(error != NULL){
        msg = @"保存图片失败" ;
    }else{
        msg = @"保存图片成功" ;
    }
    NSLog(@"%@",msg);
    //UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
  
}
@end
